package com.yuzhihao.writejvm.attributes;

import com.yuzhihao.writejvm.attributes.runtimeva.ElementValue;
import com.yuzhihao.writejvm.clazz.ClassInfo;
import com.yuzhihao.writejvm.read.Parse;
import com.yuzhihao.writejvm.read.ReadClassFileFatory;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.log4j.Log4j2;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * The AnnotationDefault attribute is a variable-length attribute in the attributes table of certain method_info structures (§4.6), namely those representing elements of annotation types (JLS §9.6.1). The AnnotationDefault attribute records the default value (JLS §9.6.2) for the element represented by the method_info structure. The Java Virtual Machine must make this default value available so it can be applied by appropriate reflective APIs.
 * <a href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.22">AnnotationDefaultAttribute</a>
 *
 * @author yzh
 * @since 2021年12月11日18:11:23
 */
@Data
@Log4j2
@EqualsAndHashCode(callSuper = true)
public class AnnotationDefaultAttribute extends Attributes {

    private ElementValue ev;

    public AnnotationDefaultAttribute(String name){
        super();
        super.setAttribute_name(name);
    }

    @Override
    public void parse(DataInputStream dis, ClassInfo ci) {
        try {
            super.attribute_length = Parse.byteToInt(super.attribute_length_u4, dis);

            char item = (char) Parse.byteToInt(ElementValue.tag_u1, dis);
            this.ev = ReadClassFileFatory.ev_instance(item);
            this.ev.parse(dis, ci);
        } catch (IOException e) {
            log.error(e);
        }
    }

}
